package bg.piss.fmi;

import bg.piss.fmi.impl.TFSCommandsManager;

/**
 * Interface, showing all methods that this Web Service should support.
 */
public class SourceControlManipulator {

    /**
     * Try to connect to given {@code versionCSUrl} with given {@code userName} and {@code password}.
     * 
     * @param versionControlURI - location of the Version Control System.
     * @param userName - name of User to use to connect to System.
     * @param password - password for authentication.
     * @return <b>Success</b> if everything is OK, or error that has occur.
     */
    public String connect(String versionControlURI, String userName, String password) {
        TFSCommandsManager manager = new TFSCommandsManager(versionControlURI, userName, password);
        return manager.connect();
    }

    /**
     * List given {@code pathToList} content.
     * 
     * @param pathToList - path to item of repository for listing, relative to repository root.
     * @param versionControlURI - location of the Version Control System.
     * @param userName - name of User to use to connect to System.
     * @param password - password for authentication.
     * @return Directory listing in correct XML format: <BR/>
     *         {@literal <DIR>}<BR/>
     *         {@literal <Folder name=""/>}<BR/>
     *         .................<BR/>
     *         {@literal <File name=""/>}<BR/>
     *         {@literal </DIR>}.<BR/>
     *         If given {@code pathToList} is file, then between {@literal <DIR></DIR>} elements, file content will be
     *         placed.
     */
    public String list(String pathToList, String versionControlURI, String userName, String password) {
        TFSCommandsManager manager = new TFSCommandsManager(versionControlURI, userName, password);
        return manager.list(pathToList);
    }

    /**
     * Delete given {@code pathToDelete} from repository.
     * 
     * @param pathToDelete - path to item to be deleted, relative to repository root.
     * @param versionControlURI - location of the Version Control System.
     * @param userName - name of User to use to connect to System.
     * @param password - password for authentication.
     * @return <b>Success</b> if everything is OK, or error that has occur.
     */
    public String delete(String pathToDelete, String versionControlURI, String userName, String password) {
        TFSCommandsManager manager = new TFSCommandsManager(versionControlURI, userName, password);
        return manager.delete(pathToDelete);
    }

    /**
     * Commit given {@code pathToDir} to repository. <b>Parents of this Directory should exists on repository</b>
     * 
     * @param pathToDir - path to item to be added, relative to repository root.
     * @param versionControlURI - location of the Version Control System.
     * @param userName - name of User to use to connect to System.
     * @param password - password for authentication.
     * @return <b>Success</b> if everything is OK, or error that has occur.
     */
    public String commitDir(String pathToDir, String versionControlURI, String userName, String password) {
        TFSCommandsManager manager = new TFSCommandsManager(versionControlURI, userName, password);
        return manager.commitDir(pathToDir);
    }

    /**
     * Commit given {@code pathToFile} and its {@code content} to repository.
     * 
     * @param pathToFile - path to item to be added, relative to repository root.
     * @param content - content of file, that is going to be added.
     * @param versionControlURI - location of the Version Control System.
     * @param userName - name of User to use to connect to System.
     * @param password - password for authentication.
     * @return <b>Success</b> if everything is OK, or error that has occur.
     */
    public String commit(String pathToFile, byte[] content, String versionControlURI, String userName, String password) {
        TFSCommandsManager manager = new TFSCommandsManager(versionControlURI, userName, password);
        return manager.commit(pathToFile, content);
    }
}
